package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;

/**
 * 分析：
 * 实现：
 * 经验：
 * 教训：
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P1041 {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1041.class.getResource("P1041.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		StringBuffer sb = new StringBuffer("");
		StringTokenizer st = null;
		while (true) {
			String line = stdin.readLine();
			if ("0 0".equals(line)) break;
			int m = 0;
			int M = 44;
			List<Edge>[][] r = new List[M][];
			for (int i = 0; i < M; i ++) {
				r[i] = new List[M];
				for (int j = 0; j < M; j ++) {
					r[i][j] = new ArrayList<Edge>();
				}
			}
			do{
				st = new StringTokenizer(line);
				int x = Integer.valueOf(st.nextToken())-1;
				int y = Integer.valueOf(st.nextToken())-1;
				int z = Integer.valueOf(st.nextToken());
				r[x][y].add(new Edge(x, y, z));
				r[y][x].add(new Edge(y, x, z));
				if (x > m) m = x;
				if (y > m) m = y;
				line = stdin.readLine();
			} while (!"0 0".equals(line));
			m ++;	//number of junctions
			
			int[] ds = new int[M];
			for (int i = 0; i < M; i ++) {
				for (int j = 0; j < M; j ++) {
					ds[i] += r[i][j].size();
				}
			}
			boolean check = true;
			for (int i = 0; i < M; i ++) {
				if (ds[i]%2 != 0) {
					check = false;
					break;
				}
			}
			if (check) {
				for (int i = 0; i < M; i ++) {
					for (int j = 0; j < M; j ++) {
						Collections.sort(r[i][j]);
					}
				}
				List<Edge> circuit = euler_circuit(r, 0);
				for (Edge edge: circuit) {
					sb.append(edge.n).append(" ");
				}
				sb.deleteCharAt(sb.length()-1);
				
				sb.append("\n");
			} else {
				sb.append("Round trip does not exist.\n");
			}
		}
		System.out.println(sb);
	}
	
	private static List<Edge> euler_circuit(List<Edge>[][] r, int i) {

		LinkedList<Edge> edges = new LinkedList<Edge>();
		LinkedList<Edge> stack = new LinkedList<Edge>();
		int u = i;
		do {
			boolean append = false;
			for (int v = 0; v < r[u].length; v ++) {
				if (r[u][v].size() > 0) {
					Edge edge = r[u][v].get(0);
					r[u][v].remove(0);
					int k = Collections.binarySearch(r[v][u], edge);
					r[v][u].remove(k);
					edges.push(edge);
					
					append = true;
					break;
				}
			}
			if (append) {
				Edge edge = edges.peek();
				u = edge.v;
			} else {
				if (edges.isEmpty()) {
					break;
				} else {
					Edge edge = edges.pop();
					stack.push(edge);
					u = edge.u;
				}
			}
		} while (true);
		
		LinkedList<Edge> list = new LinkedList<Edge>();
		while (!stack.isEmpty()) {
			Edge edge = stack.pop();
			list.push(edge);
		}

		return list;
	}
	
	private static class Edge implements Comparable<Edge> {
		int u;
		int v;
		int n;
		public Edge(int u, int v, int n) {
			this.u = u;
			this.v = v;
			this.n = n;
		}
		public String toString() {
			return "E(" + n + ":" + u + "->" + v + ")"; 
		}
		public int compareTo(Edge edge) {
			return -Integer.valueOf(this.n).compareTo(edge.n);
		}
	}
}
